<?php
/**
 * 应用自定义控制器类
 * 
 * @version $Id: AppController.php 291 2012-05-04 03:01:07Z linsir123 $
 */
class AppController extends Controller 
{
	/**
	 * @var 是否爬虫访问
	 */
	public $isRobot = false;
	
	/**
	 * @var 是否IE6访问
	 */
	public $isIE6 = false;
	
	/**
	 * 构造函数
	 */
	public function __construct()
	{
		$this->_checkHost();
			
		///
		$this->isRobot = AppView::$isRobot = Request::isRobot();
		$this->isIE6 = AppView::$isIE6 = strpos($_SERVER['HTTP_USER_AGENT'],'MSIE 6.0') !== false;
		
		///
		AppView::init();
		
		///
		View::assign('user', M::user()->data);
	}
	
	/**
	 * 输出AJAX操作结果
	 */
	public function ajax($content)
	{
		echo $content;
		///
		exit();
	}
	
	/**
	 * 跳转
	 */
	public function goto301($url)
	{
		lpSystem::h301($url);
		///
		exit();
	}
	
	/**
	 * 找不到页面
	 */
	public function miss($keyword = '')
	{
		App::getView()->engine->caching = 0;
		View::assign('keyword', $keyword);
		View::display('miss');
		///
		App::end();
	}
	
	/**
	 * 检测是否缓存
	 */
	public function checkCache($template, $cacheId = null)
	{
		if (isset($_GET['clear'])) {
			App::getView()->engine->clearCache($template.'.html', $cacheId);
			
			///
			$url = $_SERVER['REQUEST_URI'];
			$url = substr($url, 0, strpos($url, '?'));
			lpUrl::redirect($url);
		}
		
		///
		if ($this->isRobot) {
			M::topRequest()->setCaching();
			App::getView()->conf['caching'] = 0;
		}
		
		return View::isCached($template, $cacheId);
	}
	
	
	/// 以下为私有方法 ///
	
	
	/**
	 * 检测域名
	 */
	private function _checkHost()
	{
		$serverName = $_SERVER['SERVER_NAME'];
		if ($serverName != '127.0.0.1') {
			if ($serverName != 'www.e35go.com') 
				$this->goto301('http://www.e35go.com'.$_SERVER['REQUEST_URI']);
		}
	}
}
